<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<script>
  var buffer = new ArrayBuffer(12);

  console.log(buffer)

  //ArrayBuffer转字符串
  function bufferToString(buffer, callback) {
    var blob = new Blob([u]);
    var reader = new FileReader();
    reader.readAsText(blob, 'utf-8');
    reader.onload = function () {
      if(callback) {
        callback.call(null, reader.result)
      }
    }
  }

  //字符串转字符串ArrayBuffer
  function stringToBuffer(string, callback) {
    var blob = new Blob([string],{type:'text/plain;charset=utf-8'});
    var reader = new FileReader();
    reader.readAsArrayBuffer(blob);

    reader.onload = function () {
      if(callback) {
        callback.call(null, reader.result)
      }
    }
  }
</script>
</body>
</html>
